﻿
'it's not a good way to use configDelegate, but since it's here, leave it here.
'refer lpmsserv, and addhandler to initial / configChanged events.
Public Class configDelegate
    Inherits requestProcessor

    Public Const _pathidentity As String = "__INVALID_PATH__"

    Public Shared visitCounterLink As String
    Public Shared visitCounterHomepage As String
    Public Shared avatarServerUrl As String

    Protected Overrides Sub closeImpl()
        lpmsengi.finalize()
        MyBase.closeImpl()
    End Sub

    Public Overrides Sub initial(Optional ByVal config As configParser = Nothing)
        assert(Not config Is Nothing, "storoomDelegate should be initialized with a valid configuration.")
        MyBase.initial(config)

        lpmsengi.initial(config)
        Dim host As String
        Dim port As Int32
        Dim retrytimes As UInt64
        host = config.parameter(configNaming.wfileis.name, configNaming.wfileis.storoomhost, _
                                configNaming.defaultValue.wfileis.storoomhost)
        port = config.parameter(configNaming.wfileis.name, configNaming.wfileis.storoomport, _
                                configNaming.defaultValue.wfileis.storoomport)
        retrytimes = config.parameter(configNaming.wfileis.name, configNaming.wfileis.storoomretrytimes, _
                                      configNaming.defaultValue.wfileis.storoomretrytimes)
        storoomc.storoom.initial(host, port, retrytimes)

        visitCounterLink = config.parameter(configNaming.wfileis.name, _
                                            configNaming.wfileis.visitCounterLink, _
                                            configNaming.defaultValue.wfileis.visitCounterLink)
        visitCounterHomepage = config.parameter(configNaming.wfileis.name, _
                                                configNaming.wfileis.visitCounterHomepage, _
                                                configNaming.defaultValue.wfileis.visitCounterHomepage)
        recentWhitelist = New iplist(config.parameter(configNaming.wfileis.name, _
                                                      configNaming.wfileis.recentWhitelist, _
                                                      configNaming.defaultValue.wfileis.recentWhitelist))
        avatarServerUrl = config.parameter(configNaming.wfileis.name,
                                           configNaming.wfileis.avatarServerUrl,
                                           configNaming.defaultValue.wfileis.avatarServerUrl)
    End Sub

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Public Overrides Function process(ByVal context As httpContext) As Boolean
        debugassert(False, "should not be called in storoomDelegate.")
        If Not context Is Nothing Then
            context.setstatuscode(Net.HttpStatusCode.NoContent, "NO_CONTENTE")
        End If
        Return True
    End Function
End Class
